A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
-bash/zsh: umask command not not found # Windows (WSL2) sudo apt-get update sudo apt-get install execline # Debian apt-get install execline # Ubuntu apt-get install execline # Alpine apk add bash # Arch Linux pacman -S bash # Kali Linux apt-get install execline # CentOS yum install bash # Fedora dnf install bash # OS X brew install bash # Raspbian apt-get install bash # Docker docker run cmd.cat/umask umask
umask 命令,充当一组应用程序无法在文件上设置的权限。这是进程的文件模式创建掩码,不能为目录本身设置。大多数应用程序不会创建设置了执行权限的文件,因此它们的默认值为 666,然后由 umask 修改。
umask 由 open、mkdir 和其他系统调用使用创建文件以修改新设置的权限创建的文件或目录。具体来说将 umask 从 mode 参数关闭为 open mkdir。
掩码的作用是阻挡某些东西。可以把它想象成遮蔽胶带。在这种情况下,umask 就像遮蔽胶带一样,用于在创建新文件或目录时阻挡/禁用某些权限。
创建新目录时的默认权限是八进制 777 (111 111 111),创建新文件的默认权限是八进制 666 (110 110 110)。我们通过设置 umask 来阻挡/禁用某些权限。
掩码位为 1 表示阻挡/禁用该权限(就像用遮蔽胶带遮住该位一样)。
掩码位为 0 则允许该权限通过(就像没有用遮蔽胶带遮住该位一样)。
因此,八进制 022 (000 010 010) 掩码表示禁用组写入和其他用户的写入,并允许所有其他权限通过。下面是个针对新文件(默认权限为 666,umask 值为 022)的示例计算:
perm mask result ---------------------------- u 1 0 1 (pass through) 1 0 1 (pass through) 0 0 0 (pass through) ---------------------------- g 1 0 1 (pass through) 1 1 0 (disable) 0 0 0 (pass through) ---------------------------- o 1 0 1 (pass through) 1 1 0 (disable) 0 0 0 (pass through)
#include <sys/types.h> #include <sys/stat.h> umask [-S] [mask] umask [ value ]
The umask utility shall conform to the Base Definitions volume of POSIX.1‐2017, Section 12.2, Utility Syntax Guidelines. The following option shall be supported: -S Produce symbolic output. The default output style is unspecified, but shall be recognized on a subsequent invocation of umask on the same system as a mask operand to restore the previous file mode creation mask.
umask 以八进制表示法显示当前掩码:
umask
umask 以符号(人类可读)模式显示当前掩码:
umask -S
umask 对掩码进行符号化更改,以允许所有用户拥有读取权限(掩码的其余部分保持不变):
umask a+r
umask 设置掩码(使用八进制),使新建文件/目录的默认权限中的 “组用户”和“其他用户”权限全部屏蔽掉:
umask 077